#include<bits/stdc++.h>
using namespace std;

vector<int> days = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};


bool checkNums(unordered_map<int, int> &nums, int i, int j) {

    nums[i % 10]++;
    nums[j % 10]++;
    nums[i / 10]++;
    nums[j / 10]++;

    if(nums.size() != 2)	return false;

    if(nums[i % 10] != 1 && nums[i % 10] != 3)	return false;
    if(nums[j % 10] != 1 && nums[j % 10] != 3)	return false;
    if(nums[i / 10] != 1 && nums[i / 10] != 3)	return false;
    if(nums[j / 10] != 1 && nums[j / 10] != 3)	return false;

    return true;
}

set<string> computedCouple;

void computeLegalDateTime(unordered_map<int, int> nums, int &ans) {
    string t = "";

    int a, b;
    for(auto i = nums.begin(); i != nums.end(); i++) {
        if(i->second == 1) {
            a = i->first;
        } else {
            b = i->first;
        }
    }

    for(int i = 0 ; i < 2; i++) t += a + '0';
    for(int i = 0 ; i < 6; i++) t += b + '0';

    sort(t.begin(), t.end());

    if(computedCouple.count(t)) return ;

    computedCouple.insert(t);

    do {

        int month = stoi(t.substr(0, 2));
        if(1 > month || month > 12) continue;

        int day = stoi(t.substr(2, 2));
        if(1 > day || day > days[month]) continue;

        int hour = stoi(t.substr(4, 2));
        if(0 > hour || hour > 23) continue;

        int minute = stoi(t.substr(6, 2));
        if(0 > minute || minute > 59) continue;

        if(month == day) continue;
        if(hour == minute) continue;

        ans += 4;

    } while(next_permutation(t.begin(), t.end()));
}


signed main() {
//	system("start https://www.lanqiao.cn/problems/2119/learning/");

    int ans = 0;

    for(int i = 1; i <= 12; i++) {
        for(int j = 1; j <= days[i]; j++) {

            unordered_map<int, int> nums;

            if(!checkNums(nums, i, j)) continue;

            computeLegalDateTime(nums, ans);
        }
    }
    cout << ans;

    return 0;
}

